import RobotError from "../model/errors/robot-error.js";


export default class DateUtil {
	private date: Date;

	constructor() {
		this.date = new Date();
	}

	get msStamp() {
		return this.date.getTime();
	}

	get secondStamp() {
		return this.msStamp / 1000;
	}

	get minuteStamp() {
		return this.secondStamp / 60;
	}

	get hourStamp() {
		return this.minuteStamp / 60;
	}

	get dayStamp() {
		return this.hourStamp / 24;
	}

	get timeStamp() {
		return this.msStamp;
	}
	/**年份 */
	get year() {
		return this.date.getFullYear();
	}
	get yearStr() {
		return this.year.toString();
	}

	get month() {
		return this.date.getMonth() + 1;
	}
	get monthStr() {
		let month = this.month;
		return month < 10 ? '0' + month : month.toString();
	}

	get day() {
		return this.date.getDate();
	}
	get dayStr() {
		let day = this.day;
		return day < 10 ? '0' + day : day.toString();
	}

	get dateStr() {
		let date = this.yearStr + this.monthStr + this.dayStr;
		if (date.length != 8) throw new RobotError("日期字符串长度校验未通过：" + date);
		return date;
	}

}